public class ALU extends Constants {

	public static boolean Zero = false;
	public static int ALUResult = -1;

	public static void performOperation(int readData1, int readData2,
			int signExtended, ALUOp operation, boolean immediate) {
		// Temp Variables
		int TempResult = -1;
		int secondOperand = (immediate ? signExtended : readData2);

		// Operations
		switch (operation) {
		case ADD:
			TempResult = readData1 + secondOperand;
			break;
		case AND:
			TempResult = readData1 & secondOperand;
			break;
		case NOR:
			TempResult = ~(readData1 | secondOperand);
			break;
		case OR:
			TempResult = readData1 | secondOperand;
			break;
		case SLL:
			TempResult = readData1 << secondOperand;
			break;
		case SRL:
			TempResult = readData1 >>> secondOperand;
			break;
		case SUB:
			TempResult = readData1 - secondOperand;
			break;
		default:
			break;
		}

		// Output results
		switch (Instruction.opCode) {
		case SLT:
		case SLTI:
			ALUResult = readData1 < secondOperand ? 1 : 0;
			break;
		case SLTU:
			ALUResult = (((long)readData1) & 0x00000000ffffffff) < (((long)secondOperand) & 0x00000000ffffffff) ? 1 : 0;
			break;
		case SLTUI:
			ALUResult = (((long)readData1) & 0x00000000ffffffff) < (secondOperand & 0x0000ffff) ? 1 : 0;
			break;
		default:
			ALUResult = TempResult;
			break;
		}

		Zero = TempResult == 0;

	}

}
